package com.ruoyi.web.controller.officalWebsite;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.kiku.domain.*;
import com.ruoyi.kiku.domain.model.EndorsementNavs;
import com.ruoyi.kiku.service.*;
import com.ruoyi.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 橘事顺利官网api
 *
 * @author: 披荆斩棘
 * @date: 2017/7/19
 */
@RestController
@RequestMapping("/officialWebSite")
public class JuShiShunLiOfficialWebsiteApiController extends BaseController {

    @Autowired
    private IOfficialWebsiteBannerInfoService officialWebsiteBannerInfoService;
    @Autowired
    private IKikuDeedsService kikuDeedsService;
    @Autowired
    private SysLoginService loginService;
    @Autowired
    private IKikuEndorsementsService kikuEndorsementsService;
    @Autowired
    private IKikuNewsInfoService kikuNewsInfoService;
    @Autowired
    private IKikuRelationalNewsService kikuRelationalNewsService;
    @Autowired
    private ISysDictTypeService dictTypeService;
    @Autowired
    private IJsslArtistsInfoService jsslArtistsInfoService;
    @Autowired
    private IJsslArtistsWorksService jsslArtistsWorksService;

    /**
     *  官网接口授权接口
     * @return 结果
     */
    @PostMapping("/auth")
    public AjaxResult officialWebSiteAuth(HttpServletResponse response) {
        String token = loginService.officialWebSiteAuth();
        response.setHeader("Access-Control-Expose-Headers", "Authorization");
        response.setHeader("Authorization", "Bearer " + token);
        return AjaxResult.success();
    }

    /**
     * 查询轮播信息列表
     */
    @GetMapping("/bannerInfo")
    public AjaxResult bannerInfo()
    {
        return success(officialWebsiteBannerInfoService.selectOfficialWebsiteBannerInfoListFromRedis());
    }
    /**
     * 查询小鞠事迹列表
     */
    @GetMapping("/deedsList")
    public TableDataInfo deedsList(KikuDeeds kikuDeeds)
    {
        startPage();
        List<KikuDeeds> list = kikuDeedsService.selectKikuDeedsList(kikuDeeds);
        return getDataTable(list);
    }
    /**
     *  查询小鞠代言导航
     */
    @GetMapping("/endorsementsNavigation")
    public AjaxResult endorsementsNavigation() {
       List<EndorsementNavs> list= kikuEndorsementsService.selectKikuEndorsementsNavigationList();
       return success(list);
    }

    /**
     * 获取小鞠代言详细信息
     */
    @PreAuthorize("@ss.hasPermi('kiku:endorsements:query')")
    @GetMapping(value = "/selectEndorsementById/{id}")
    public AjaxResult selectEndorsementById(@PathVariable("id") Long id)
    {
        return success(kikuEndorsementsService.selectKikuEndorsementsById(id));
    }

    /**
     * 查询小鞠代言列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:endorsements:list')")
    @GetMapping("/endorsements")
    public AjaxResult endorsements()
    {
        List<KikuEndorsements> list = kikuEndorsementsService.selectKikuEndorsementsList(new KikuEndorsements());
        return success(list);
    }

    /**
     * 查询小鞠新闻列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:newsInfo:list')")
    @GetMapping("/newsList")
    public TableDataInfo newsList(KikuNewsInfo kikuNewsInfo)
    {
        startPage();
        List<KikuNewsInfo> list = kikuNewsInfoService.selectKikuNewsInfoList2(kikuNewsInfo);
        return getDataTable(list);
    }
    /**
     * 获取小鞠新闻详细信息
     */
    @PreAuthorize("@ss.hasPermi('kiku:newsInfo:query')")
    @GetMapping(value = "/news/{id}")
    public AjaxResult newsInfo(@PathVariable("id") Long id)
    {
        return success(kikuNewsInfoService.selectKikuNewsInfoById(id));
    }

    /**
     * 根据新闻id查询关联新闻列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:relationalNews:query')")
        @GetMapping(value = "/relationalNews/{newsId}")
    public AjaxResult getRelationalNewsInfo(@PathVariable("newsId") Long newsId)
    {
        return success(kikuRelationalNewsService.selectKikuRelationalNewsListByNewsId(newsId));
    }

    /**
     * 根据字典类型查询字典数据信息
     */
    @GetMapping(value = "/getDict/{dictType}")
    public AjaxResult dictType(@PathVariable String dictType)
    {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data))
        {
            data = new ArrayList<SysDictData>();
        }
        return success(data);
    }



    /**
     * 查询橘事顺利艺术家列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:artistsInfo:list')")
    @GetMapping("/artistsInfo")
    public TableDataInfo artistsInfo(JsslArtistsInfo jsslArtistsInfo)
    {
        startPage();
        List<JsslArtistsInfo> list = jsslArtistsInfoService.selectJsslArtistsInfoList2(jsslArtistsInfo);
        return getDataTable(list);
    }

    /**
     * 查询橘事顺利鞠婧祎作品列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:artistsWorks:list')")
    @GetMapping("/artistsWorks")
    public TableDataInfo artistsWorks(JsslArtistsWorks jsslArtistsWorks)
    {
        startPage();
        List<JsslArtistsWorks> list = jsslArtistsWorksService.selectJsslArtistsWorksList2(jsslArtistsWorks);
        return getDataTable(list);
    }


}
